package org.groupg.practice;

import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.ints.IntArrayList;

public class FastUtilMapExample {
    public static void main(String[] args) {
        // 构建一个以 int 为键、Object 为值的映射，指定初始容量和负载因子
        Int2ObjectOpenHashMap<IntArrayList> graph = new Int2ObjectOpenHashMap<>(1024, 0.75f);

        // 设置一个特殊的默认返回值，用于区分"键不存在"
        graph.defaultReturnValue(null);

        int nodeId = 1001;
        IntArrayList neighbors = new IntArrayList();
        neighbors.add(1002);
        neighbors.add(1003);

        // 将列表与节点ID关联
        graph.put(nodeId, neighbors);

        // 获取邻居列表
        IntArrayList retrievedNeighbors = graph.get(nodeId);
        if (retrievedNeighbors != null) {
            // 使用 IntListIterator 进行高效遍历，避免装箱
            for (int neighbor : retrievedNeighbors) {
                System.out.println("Neighbor: " + neighbor);
            }
        }
    }
}